package com.mf.ergate.controller.opt;

import com.mf.ergate.api.opt.OrgContractRemoteService;
import com.mf.ergate.api.opt.model.dto.OrgContractCreateDto;
import com.mf.ergate.api.opt.model.dto.OrgContractDeleteDto;
import com.mf.ergate.api.opt.model.dto.OrgContractQueryDto;
import com.mf.ergate.api.opt.model.dto.OrgContractUpdateDto;
import com.mf.ergate.api.opt.model.vo.OrgContractVo;
import com.mf.ergate.common.utils.MfBeanUtils;
import com.mf.ergate.domain.model.opt.OrgContractEntity;
import com.mf.ergate.service.opt.OrgContractService;
import com.mf.framework.common.model.Page;
import com.mf.framework.common.model.RemotePage;
import com.mf.framework.common.model.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 机构合同Controller
 * User: zhaoming
 * DateTime: 2019-04-16
 * To change this template use File | Settings | File Templates.
 */
@RestController
public class OrgContractController implements OrgContractRemoteService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private OrgContractService orgContractService;

    /**
     * 新增
     * @param orgContractCreateDto 机构合同新增Dto
     * @return 机构合同
     */
    public Result<OrgContractVo> insert(@RequestBody OrgContractCreateDto orgContractCreateDto) {
        OrgContractEntity orgContractEntity = MfBeanUtils.copyObject(orgContractCreateDto, OrgContractEntity.class);
        orgContractEntity = orgContractService.insert(orgContractEntity);
        OrgContractVo orgContractVo = MfBeanUtils.copyObject(orgContractEntity, OrgContractVo.class);
        return new Result<>(orgContractVo);
    }

    /**
     * 根据唯一编号更新
     * @param orgContractUpdateDto 机构合同更新Dto
     * @return 执行结果
     */
    public Result<Boolean> updateByUniqueNo(@RequestBody OrgContractUpdateDto orgContractUpdateDto) {
        OrgContractEntity orgContractEntity = MfBeanUtils.copyObject(orgContractUpdateDto, OrgContractEntity.class);
        Boolean flag = orgContractService.updateByUniqueNo(orgContractEntity);
        return new Result<>(flag);
    }

    /**
     * 根据唯一编号删除(逻辑删除)
     * @param orgContractDeleteDto 机构合同删除Dto
     * @return 结果集
     */
    public Result<Boolean> deleteByUniqueNo(@RequestBody OrgContractDeleteDto orgContractDeleteDto){
        OrgContractEntity orgContractEntity = MfBeanUtils.copyObject(orgContractDeleteDto, OrgContractEntity.class);
        Boolean flag = orgContractService.deleteByUniqueNo(orgContractEntity);
        return new Result<>(flag);
    }

    /**
     * 根据唯一编号查询
     * @param uniqueNo 唯一编号
     * @return 机构合同
     */
    public Result<OrgContractVo> selectByUniqueNo(@RequestBody String uniqueNo) {
        OrgContractEntity orgContractEntity = orgContractService.selectByUniqueNo(uniqueNo);
        OrgContractVo orgContractVo = MfBeanUtils.copyObject(orgContractEntity, OrgContractVo.class);
        return new Result<>(orgContractVo);
    }

    /**
     * 根据条件查询
     * @param orgContractQueryDto 机构合同查询Dto
     * @return 机构合同列表
     */
    public Result<List<OrgContractVo>> selectByCondition(@RequestBody OrgContractQueryDto orgContractQueryDto) {
        List<OrgContractEntity> orgContractEntities = orgContractService.selectByCondition(orgContractQueryDto);
        List<OrgContractVo> orgContractVos = MfBeanUtils.copyList(orgContractEntities, OrgContractVo.class);
        return new Result<>(orgContractVos);
    }

    /**
     * 根据条件查询数量
     * @param orgContractQueryDto 机构合同查询Dto
     * @return 数量
     */
    public Result<Integer> selectCount(@RequestBody OrgContractQueryDto orgContractQueryDto) {
        return new Result<>(orgContractService.selectCount(orgContractQueryDto));
    }

    /**
     * 根据条件分页查询
     * @param remotePage 远程分页对象
     * @return 机构合同分页列表
     */
    public Result<Page<OrgContractVo>> selectPage(@RequestBody RemotePage<OrgContractQueryDto> remotePage){
        Page<OrgContractEntity> orgContractEntityPage = orgContractService.selectPage(remotePage.getPage(), remotePage.getObj());
        Page<OrgContractVo> page = MfBeanUtils.copyPage(orgContractEntityPage, OrgContractVo.class);
        return new Result<>(page);
    }

}